Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports DotNetNuke
Imports DotNetNuke.Framework.Providers

'TODO: To compile, build the main ProjectTracker module first, copy it's DLL to the main DotNetNuke bin directory, and add a reference to it within this project's references.

Namespace DotNetNuke.Modules.ProjectTracker

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    '''		The SqlDataProvider Class is a SQL Server implementation of the DataProvider
    '''		abstract class that provides the DataLayer for the ProjectTracker module.
    ''' </summary>
    ''' <remarks></remarks>
    ''' <history>
    '''		[MyGeneration]	3/18/2006 3:35:55 PM	Code file automatically generated from DotNetNuke by MyGeneration v1.1.5.1
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Public Class SqlDataProvider

        Inherits DataProvider

#Region " Private Fields "

        Private Const ProviderType As String = "data"

        Private _providerConfiguration As Framework.Providers.ProviderConfiguration = Framework.Providers.ProviderConfiguration.GetProviderConfiguration(ProviderType)
        Private _connectionString As String
        Private _providerPath As String
        Private _objectQualifier As String
        Private _databaseOwner As String

#End Region

#Region " Constructor "

        Public Sub New()

            ' Read the configuration specific information for this provider
            Dim objProvider As Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Framework.Providers.Provider)

            ' Read the attributes for this provider
            If objProvider.Attributes("connectionStringName") <> "" AndAlso _
            System.Configuration.ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName")) <> "" Then
                _connectionString = System.Configuration.ConfigurationSettings.AppSettings(objProvider.Attributes("connectionStringName"))
            Else
                _connectionString = objProvider.Attributes("connectionString")
            End If

            _providerPath = objProvider.Attributes("providerPath")

            _objectQualifier = objProvider.Attributes("objectQualifier")
            If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
                _objectQualifier += "_"
            End If

            _databaseOwner = objProvider.Attributes("databaseOwner")
            If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
                _databaseOwner += "."
            End If

        End Sub

#End Region

#Region " Properties "

        Public ReadOnly Property ConnectionString() As String
            Get
                Return _connectionString
            End Get
        End Property

        Public ReadOnly Property ProviderPath() As String
            Get
                Return _providerPath
            End Get
        End Property

        Public ReadOnly Property ObjectQualifier() As String
            Get
                Return _objectQualifier
            End Get
        End Property

        Public ReadOnly Property DatabaseOwner() As String
            Get
                Return _databaseOwner
            End Get
        End Property

#End Region

        Private Function GetNull(ByVal Field As Object) As Object
            Return DotNetNuke.Common.Utilities.Null.GetNull(Field, DBNull.Value)
        End Function

#Region " Projects methods "

        Public Overrides Function AddProjects(ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal projectName As String, ByVal version As String, ByVal projectLead As Integer, ByVal projectChair As Integer, ByVal description As String, ByVal url As String, ByVal currentState As Integer, ByVal status As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddProjects", moduleID, createdByUser, createdDate, projectName, version, projectLead, projectChair, description, url, currentState, status), Integer)
        End Function

        Public Overrides Sub UpdateProjects(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal projectName As String, ByVal version As String, ByVal projectLead As Integer, ByVal projectChair As Integer, ByVal description As String, ByVal url As String, ByVal currentState As Integer, ByVal status As String)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateProjects", itemID, moduleID, createdByUser, createdDate, projectName, version, projectLead, projectChair, description, url, currentState, status)
        End Sub

        Public Overrides Sub DeleteProjects(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteProjects", itemID)
        End Sub

        Public Overrides Function GetProjectsInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetProjectsInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetProjectsList(ByVal moduleID As Integer, ByVal filter As String) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetProjectsList", moduleID, filter), IDataReader)
        End Function

#End Region

#Region " Process methods "

        Public Overrides Function AddProcess(ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal workflowName As String, ByVal description As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddProcess", moduleID, createdByUser, createdDate, workflowName, description), Integer)
        End Function

        Public Overrides Sub UpdateProcess(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal workflowName As String, ByVal description As String)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateProcess", itemID, moduleID, createdByUser, createdDate, workflowName, description)
        End Sub

        Public Overrides Sub DeleteProcess(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteProcess", itemID)
        End Sub

        Public Overrides Function GetProcessInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetProcessInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetProcessList(ByVal moduleID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetProcessList", moduleID), IDataReader)
        End Function

#End Region

#Region " States methods "

        Public Overrides Function AddStates(ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal stateName As String, ByVal description As String, ByVal status As Integer, ByVal processOrder As Integer, ByVal subscriberRoles As String, ByVal authorizedRoles As String, ByVal notes As String, ByVal entrySubject As String, ByVal entryBody As String, ByVal passSubject As String, ByVal passBody As String, ByVal failSubject As String, ByVal failBody As String, ByVal downloadroles As String, ByVal commentroles As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddStates", moduleID, createdByUser, createdDate, stateName, description, status, processOrder, subscriberRoles, authorizedRoles, notes, entrySubject, entryBody, passSubject, passBody, failSubject, failBody, downloadroles, commentroles), Integer)
        End Function

        Public Overrides Sub UpdateStates(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal stateName As String, ByVal description As String, ByVal status As Integer, ByVal processOrder As Integer, ByVal subscriberRoles As String, ByVal authorizedRoles As String, ByVal notes As String, ByVal entrySubject As String, ByVal entryBody As String, ByVal passSubject As String, ByVal passBody As String, ByVal failSubject As String, ByVal failBody As String, ByVal downloadroles As String, ByVal commentroles As String)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateStates", itemID, moduleID, createdByUser, createdDate, stateName, description, status, processOrder, subscriberRoles, authorizedRoles, notes, entrySubject, entryBody, passSubject, passBody, failSubject, failBody, downloadroles, commentroles)
        End Sub

        Public Overrides Sub DeleteStates(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteStates", itemID)
        End Sub

        Public Overrides Function GetStatesInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetStatesInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetStatesList(ByVal moduleID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetStatesList", moduleID), IDataReader)
        End Function

#End Region

#Region " History methods "

        Public Overrides Function AddHistory(ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal projectID As Integer, ByVal activity As String, ByVal activityType As String, ByVal objectID As Integer) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddHistory", moduleID, createdByUser, createdDate, projectID, activity, activityType, objectID), Integer)
        End Function

        Public Overrides Sub UpdateHistory(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal projectID As Integer, ByVal activity As String, ByVal activityType As String, ByVal objectID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateHistory", itemID, moduleID, createdByUser, createdDate, projectID, activity, activityType, objectID)
        End Sub

        Public Overrides Sub DeleteHistory(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteHistory", itemID)
        End Sub

        Public Overrides Function GetHistoryInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetHistoryInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetHistoryList(ByVal projectID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetHistoryList", projectID), IDataReader)
        End Function

        Public Overrides Function GetHistoryActivity(ByVal projectID As Integer, ByVal activity As String) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetHistoryActivity", projectID, activity), IDataReader)
        End Function

        Public Overrides Function GetHistoryActivityByType(ByVal projectID As Integer, ByVal activityType As String, ByVal objectID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetHistoryActivityByType", projectID, activityType, objectID), IDataReader)
        End Function

        Public Overrides Function GetHistoryListByType(ByVal projectID As Integer, ByVal activityType As String, ByVal objectID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetHistoryListByType", projectID, activityType, objectID), IDataReader)
        End Function

#End Region

#Region " ExitCriteria methods "

        Public Overrides Function AddExitCriteria(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal stateID As Integer, ByVal criteria As String, ByVal description As String) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddExitCriteria", moduleID, createdByUser, createdDate, stateID, criteria, description), Integer)
        End Function

        Public Overrides Sub UpdateExitCriteria(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal stateID As Integer, ByVal criteria As String, ByVal description As String)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateExitCriteria", itemID, moduleID, createdByUser, createdDate, stateID, criteria, description)
        End Sub

        Public Overrides Sub DeleteExitCriteria(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteExitCriteria", itemID)
        End Sub

        Public Overrides Function GetExitCriteriaInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetExitCriteriaInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetExitCriteriaList(ByVal stateID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetExitCriteriaList", stateID), IDataReader)
        End Function

#End Region

#Region " StateSubscribers methods "

        Public Overrides Function AddStateSubscribers(ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal eMail As String, ByVal stateID As Integer, ByVal subscriptionType As Integer) As Integer
            Return CType(SqlHelper.ExecuteScalar(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_AddStateSubscribers", moduleID, createdByUser, createdDate, eMail, stateID, subscriptionType), Integer)
        End Function

        Public Overrides Sub UpdateStateSubscribers(ByVal itemID As Integer, ByVal moduleID As Integer, ByVal createdByUser As Integer, ByVal createdDate As DateTime, ByVal eMail As String, ByVal stateID As Integer, ByVal subscriptionType As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_UpdateStateSubscribers", itemID, moduleID, createdByUser, createdDate, eMail, stateID, subscriptionType)
        End Sub

        Public Overrides Sub DeleteStateSubscribers(ByVal itemID As Integer)
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_DeleteStateSubscribers", itemID)
        End Sub

        Public Overrides Function GetStateSubscribersInfo(ByVal itemID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner + ObjectQualifier + "PT_GetStateSubscribersInfo", itemID), IDataReader)
        End Function

        Public Overrides Function GetStateSubscribersList(ByVal stateID As Integer, ByVal typeID As Integer) As IDataReader
            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "PT_GetStateSubscribersList", stateID, typeID), IDataReader)
        End Function

#End Region

    End Class
End Namespace
